﻿//以下是程序引用页面的定义
var editMScode = "managerDocEdit.aspx"; //编辑MS OFFICE文档页面程序
var editWPScode = "editwps.aspx"; //编辑WPS文档页面程序
var savecode = "managerFileSave.aspx"; //保存文档程序程序
var readcode = "read.aspx"; //读取后台二进制数据程序
var delcode = "delete.aspx"; //执行数据删除后台程序
var editMSOthePara = "";
var redrectUrl = "";

//以下变量为JS公共变量
var TANGER_OCX_bDocOpen = false;
var TANGER_OCX_filename; //文件名称
var filetype; //文件类型
var savetype; //文件保存类型
var TANGER_OCX_actionURL; //For auto generate form fiields
var TANGER_OCX_OBJ; //控件对象
var TANGER_OCX_Username = "匿名用户"; //User Name
var TANGER_OCX_key = ""; //设置加载印章的key
var IsFileOpened;  //控件是否打开文档
var svisble = true; //印章显示状态
var url = ""; //初始化URL值
var newwin, newdoc;

//创建新的文档
function CreatNew(newofficetype) {
    //根据传递文档类型参数新建文档
    switch (newofficetype) {
        case "1":
            openoffice(url, newofficetype)
            break
        case "2":
            openoffice(url, newofficetype)
            break
        case "3":
            openoffice(url, newofficetype)
            break
        case "4":
            openoffice(url, newofficetype)
            break
        case "5":
            openoffice(url, newofficetype)
            break
        default:
            openoffice(url, "1")
            break;
    }
}
function openoffice(url, newofficetype) {
    window.open(editMScode + "?newofficetype=" + newofficetype + "&url=" + url + editMSOthePara, "editoffice", "top=0,left=0,scrollbars=yes,resizable=yes");
}
//当前表单不可编辑,当整个表单只读时调用
function FormDisabled(bool) {
    var formid = document.forms.item(0)
    var elelength = formid.length;
    for (var i = 0; i < elelength; i++)
    { formid.elements[i].disabled = bool; }
    //下面是控件标题栏,状态栏,工具栏,菜单栏不显示
    TANGER_OCX_OBJ.TitleBar = !bool;
    TANGER_OCX_OBJ.Statusbar = !bool;
    TANGER_OCX_OBJ.ToolBars = !bool;
    TANGER_OCX_OBJ.Menubar = !bool;
    document.getElementById("editmain_left").style.display = "none";
    document.getElementById("editmain_right").style.width = "95%";
}
//示例程序帮助文档
function NtkoHelp() {
    window.open("help.htm", "help");
}
//编辑文档
function editoffice(url, newofficetype) {
    TANGER_OCX_OBJ = document.all.item("TANGER_OCX"); //;初始化控件对象
    TANGER_OCX_OBJ.Close();
    setIsNoCopy(false);
    //根据文档URL和newofficetype编辑文档,如果有url是编辑已有文档,如果为空根据newofficetype新建文档
    if ((typeof (url) != "undefined") && (url != "")) {
        //var filename = document.all("filename").value;
        
        try {
            var l =url.length;
            var dot = url.substr(url.lastIndexOf('.')+1, l);
            dot = dot.toUpperCase();
            if ("DOC" == dot || "XLS" == dot || "PPT" == dot
                || "DOCX" == dot || "XLSX" == dot || "PPTX" == dot
            
            ) {
                TANGER_OCX_OBJ.BeginOpenFromURL(url);
            }
            else {
                parent.location = url;
            }
            
        }
        catch (err) { };
    }
    else {
        switch (newofficetype) {
            //新建文档  
            case "1":
                TANGER_OCX_OBJ.CreateNew("word.document"); //word文档
                break
            case "2":
                TANGER_OCX_OBJ.CreateNew("excel.sheet"); //excel电子表格
                break
            case "3":
                TANGER_OCX_OBJ.CreateNew("PowerPoint.Show"); //微软幻灯片
                break
            case "4":
                TANGER_OCX_OBJ.CreateNew("WPS.Document"); //金山文档
                break
            case "5":
                TANGER_OCX_OBJ.CreateNew("ET.WorkBook"); //金山电子表格
                break
            default:
                alert("文档编辑出错!")
                break
        }
    }
}
function intializePage() {
    TANGER_OCX_OBJ = document.all("TANGER_OCX");
    
}
//文档编辑页面关闭事件
function onPageClose() {
    if (IsFileOpened) {
        if (!TANGER_OCX_OBJ.ActiveDocument.Saved) {
            //if (confirm("文档修改过,还没有保存,是否需要保存?")) {
               // saveFileToUrl();
            //}
            
        }
        if (window.opener != null) {
            //window.opener.location.reload();
            window.opener.location.href = window.opener.location.href;
        }
    }
}
function TANGER_OCX_OpenDoc(fileUrl) {
    if (fileUrl != null || fileUrl != "") {
        TANGER_OCX_OBJ.BeginOpenFromURL(fileUrl);
    }
    else {
        TANGER_OCX_OBJ.BegingOpenFromURL("templateFile/newWordTemplate.doc")
    }
}
//设置文件是打开还是关闭
function setFileOpenedOrClosed(bool) {
    IsFileOpened = bool;
    fileType = TANGER_OCX_OBJ.DocType;
}
function trim(str) { //删除左右两端的空格
    return str.replace(/(^\s*)|(\s*$)/g, "");
}
function erropen(retHTML) {
    newwin = window.open("", "_blank", "left=200,top=200,width=400,height=300,status=0,toolbar=0,menubar=0,location=0,scrollbars=1,resizable=1", false);
    newdoc = newwin.document;
    newdoc.open();
    newdoc.write("<html><head><title>返回的数据</title></head><body><center><hr>")
    newdoc.write(retHTML + "kdkd<hr>");
    newdoc.write("<input type=button VALUE='关闭窗口' onclick='window.close();'>");
    newdoc.write('</center></body></html>');
    newdoc.close();
}
//保存office文档
function saveFileToUrl(fileName) {
    if (fileName.length == 0) { alert("请输入文件标题!"); }

    var result, filedot;
    if (IsFileOpened) {
        switch (TANGER_OCX_OBJ.doctype) {
            case 1:
                fileType = "Word.Document";
                filedot = ".doc";
                break;
            case 2:
                fileType = "Excel.Sheet";
                filedot = ".xls";
                break;
            case 3:
                fileType = "PowerPoint.Show";
                filedot = ".ppt";
                break;
            case 4:
                fileType = "Visio.Drawing";
                filedot = ".vso"
                break;
            case 5:
                fileType = "MSProject.Project";
                filedot = ".pro";
                break;
            case 6:
                fileType = "WPS Doc";
                filedot = ".wps";
                break;
            case 7:
                fileType = "Kingsoft Sheet";
                filedot = ".et";
                break;
            default:
                fileType = "unkownfiletype";
                filedot = ".doc";
        }
        
        retHTML = TANGER_OCX_OBJ.saveToURL(savecode, //提交到的url地址
		"EDITFILE", //文件域的id，类似<input type=file id=upLoadFile 中的id
        //"savetype=1&fileType=" + fileType + "&docid=" + docid + "&dirid=" + dirid + "&fileName=" + fileName + "&seq=" + seq + "showDate=" + showDate,          //与控件一起提交的参数,savetype参数为要保存的文件格式office,html,pdf。filetype参数保存文件类型
        "savetype=1&fileType=" + fileType,    //与控件一起提交的参数,savetype参数为要保存的文件格式office,html,pdf。filetype参数保存文件类型
		fileName + filedot,    //上传文件的名称，类似<input type=file 的value
		0  //与控件一起提交的表单id，也可以是form的序列号，这里应该是0.
		);
        switch (TANGER_OCX_OBJ.StatusCode) {
            case 0:

                var arr = retHTML.split('|');
                if (arr.length == 2) {
                    if (arr[0] == "ok") {
                        alert("文件保存成功");
                        if (window.opener != null) {
                            window.opener.createOfficeOK(arr[1]); //执行上级页面方法
                        }
                        window.close();

                    } else if (arr[0] == "error") {
                        alert(arr[1]);
                    }

                }

                break;
            case 1:
                erropen(retHTML);
                break;
            case 2:
                erropen(retHTML);
                break;
            case 3:
                erropen(retHTML);
                break;
            case 4:
                erropen(retHTML);
                break;
            case 5:
                erropen(retHTML);
                break;
            case 6:
                erropen(retHTML);
                break;
            case 100:
                erropen(retHTML);
                break;
        }
    }
    else {
        alert("不能执行保存,没有编辑文档!");
    }
}

//目录生成调用
function saveFileToUrlEAccount() {
    var fileName = trim(document.all("filetitle").value);
    if (fileName.length == 0) { alert("请输入文件标题!"); document.all("filetitle").focus(); return false; } //判断文件标题输入域
    var result, filedot;
    if (IsFileOpened) {
        switch (TANGER_OCX_OBJ.doctype) {
            case 1:
                fileType = "Word.Document";
                filedot = ".doc";
                break;
            case 2:
                fileType = "Excel.Sheet";
                filedot = ".xls";
                break;
            case 3:
                fileType = "PowerPoint.Show";
                filedot = ".ppt";
                break;
            case 4:
                fileType = "Visio.Drawing";
                filedot = ".vso"
                break;
            case 5:
                fileType = "MSProject.Project";
                filedot = ".pro";
                break;
            case 6:
                fileType = "WPS Doc";
                filedot = ".wps";
                break;
            case 7:
                fileType = "Kingsoft Sheet";
                filedot = ".et";
                break;
            default:
                fileType = "unkownfiletype";
                filedot = ".doc";
        }

        retHTML = TANGER_OCX_OBJ.saveToURL(savecode, //提交到的url地址
		"EDITFILE", //文件域的id，类似<input type=file id=upLoadFile 中的id
		"savetype=1&fileType=" + fileType,          //与控件一起提交的参数,savetype参数为要保存的文件格式office,html,pdf。filetype参数保存文件类型
		fileName + filedot,    //上传文件的名称，类似<input type=file 的value
		0  //与控件一起提交的表单id，也可以是form的序列号，这里应该是0.
		);
        switch (TANGER_OCX_OBJ.StatusCode) {
            case 0:
                alert("文件保存成功");
                window.close();
                //window.returnValue = 1;
                //
                //                if (redrectUrl != "") {
                //                    window.location.href = redrectUrl;
                //                }
                //                else {
                //                    window.close();
                //                }
               
                //window.opener.location = window.opener.location;

                //                var indexa = retHTML.indexOf("ID:");
                //                var indexb = retHTML.indexOf("</br>");
                //                var locationhref = retHTML.substring(indexa + 3, indexb);
                //                window.location.href = editMScode + "?&url=" + locationhref;
                break;
            case 1:
                erropen(retHTML);
                break;
            case 2:
                erropen(retHTML);
                break;
            case 3:
                erropen(retHTML);
                break;
            case 4:
                erropen(retHTML);
                break;
            case 5:
                erropen(retHTML);
                break;
            case 6:
                erropen(retHTML);
                break;
            case 100:
                erropen(retHTML);
                break;
        }
    }
    else {
        alert("不能执行保存,没有编辑文档!");
    }
}




//保存office文档,DOC专用
function saveFileToUrlDOC(fileName) {
//    var fileName = trim(document.all("filetitle").value);
//    if (fileName.length == 0) { alert("请输入文件标题!"); document.all("filetitle").focus(); return false; } //判断文件标题输入域
    var result, filedot;
    if (IsFileOpened) {
        switch (TANGER_OCX_OBJ.doctype) {
            case 1:
                fileType = "Word.Document";
                filedot = ".doc";
                break;
            case 2:
                fileType = "Excel.Sheet";
                filedot = ".xls";
                break;
            case 3:
                fileType = "PowerPoint.Show";
                filedot = ".ppt";
                break;
            case 4:
                fileType = "Visio.Drawing";
                filedot = ".vso"
                break;
            case 5:
                fileType = "MSProject.Project";
                filedot = ".pro";
                break;
            case 6:
                fileType = "WPS Doc";
                filedot = ".wps";
                break;
            case 7:
                fileType = "Kingsoft Sheet";
                filedot = ".et";
                break;
            default:
                fileType = "unkownfiletype";
                filedot = ".doc";
        }

        retHTML = TANGER_OCX_OBJ.saveToURL(savecode, //提交到的url地址
		"EDITFILE", //文件域的id，类似<input type=file id=upLoadFile 中的id
		"savetype=1&fileType=" + fileType,          //与控件一起提交的参数,savetype参数为要保存的文件格式office,html,pdf。filetype参数保存文件类型
		fileName + filedot,    //上传文件的名称，类似<input type=file 的value
		0  //与控件一起提交的表单id，也可以是form的序列号，这里应该是0.
		);
        if (retHTML != "") {
          var strMessages = retHTML.split('|');
          var message=strMessages[0];
            switch(message){
                case "ok":
                    {
                        alert("保存成功!");
                        window.location.href = strMessages[1];
                    } break;
                case "ok1":
                    {
                        alert("保存成功,但信息推送到JCMS失败!");
                        window.location.href = strMessages[1];
                    } break;
                case "error":alert(strMessages[1]);break;
            }
        }
        
		

    }
    else {
        alert("不能执行保存,没有编辑文档!");
    }
}



//保存文档为html文件到服务器 DOC
function saveFileAsHtmlToUrlDOC() {
    var fileName = trim(document.all("filetitle").value);
    if (fileName.length == 0) { alert("请输入文件标题!"); document.all("filetitle").focus(); return false; } //判断文件标题输入域
    var result, filedot;
    if (IsFileOpened) {
        switch (TANGER_OCX_OBJ.doctype) {
            case 1:
                fileType = "Word.Document";
                filedot = ".doc";
                break;
            case 2:
                fileType = "Excel.Sheet";
                filedot = ".xls";
                break;
            case 3:
                fileType = "PowerPoint.Show";
                filedot = ".ppt";
                break;
            case 4:
                fileType = "Visio.Drawing";
                filedot = ".vso"
                break;
            case 5:
                fileType = "MSProject.Project";
                filedot = ".pro";
                break;
            case 6:
                fileType = "WPS Doc";
                filedot = ".wps";
                break;
            case 7:
                fileType = "Kingsoft Sheet";
                filedot = ".et";
                break;
            default:
                fileType = "unkownfiletype";
                filedot = ".doc";
        }


        retHTML = TANGER_OCX_OBJ.PublishAsHTMLToURL(savecode, //提交到的url地址
        		"EDITFILE", //文件域的id，类似<input type=file id=upLoadFile 中的id
        		"savetype=2&fileType=" + fileType,          //与控件一起提交的参数,savetype参数为要保存的文件格式office,html,pdf。filetype参数保存文件类型
        		fileName,    //上传文件的名称，类似<input type=file 的value
        		0  //与控件一起提交的表单id，也可以是form的序列号，这里应该是0.
        		);

                
        //千航工作人员发过来的代码
        //var filename = document.form1.filename.value;
        //        var result;
        //        if (IsFileOpened) {
        //            result = OFFICE_NTKO_OBJ.PublishAsHtmlToURL("uploadhtmlFile.jsp",
        //        			"uploadHtml",
        //        			"",
        //        			filename,
        //        			0);
        //        }
        //        alert(result);
        


        //        result = TANGER_OCX_OBJ.PublishAsHtmlToURL(savecode,
        //        			"EDITFILE",
        //        			"",
        //        			fileName,
        //        			0);

        //        alert(result);
        


    }
    else {
        alert("不能执行保存,没有编辑文档!");
    }
}





//保存office文档1
function saveFileToUrl1() {
    var fileName = "test.doc";
    if (fileName.length == 0) { alert("请输入文件标题!"); document.all("filetitle").focus(); return false; } //判断文件标题输入域
    var result,
        retHTML = TANGER_OCX_OBJ.saveToURL(savecode, //提交到的url地址
		"EDITFILE", //文件域的id，类似<input type=file id=upLoadFile 中的id
		"savetype=1&fileType=doc",          //与控件一起提交的参数,savetype参数为要保存的文件格式office,html,pdf。filetype参数保存文件类型
		fileName,    //上传文件的名称，类似<input type=file 的value
		0  //与控件一起提交的表单id，也可以是form的序列号，这里应该是0.
		);
    newwin = window.open("", "_blank", "left=200,top=200,width=400,height=300,status=0,toolbar=0,menubar=0,location=0,scrollbars=1,resizable=1", false);
    newdoc = newwin.document;
    newdoc.open();
    newdoc.write("<center><hr>" + retHTML + "<hr><input type=button VALUE='关闭窗口' onclick='window.close();if(window.opener){window.opener.location.reload()};'></center>");
    newdoc.close();
    window.opener.focus();
}
//保存文档为html文件到服务器
function saveFileAsHtmlToUrl() {
    var fileName = trim(document.all("filetitle").value);
    if (fileName.length == 0) { alert("请输入文件标题!"); document.all("filetitle").focus(); return false; } //判断文件标题输入域
    var result, filedot;
    if (IsFileOpened) {
        switch (TANGER_OCX_OBJ.doctype) {
            case 1:
                fileType = "Word.Document";
                filedot = ".doc";
                break;
            case 2:
                fileType = "Excel.Sheet";
                filedot = ".xls";
                break;
            case 3:
                fileType = "PowerPoint.Show";
                filedot = ".ppt";
                break;
            case 4:
                fileType = "Visio.Drawing";
                filedot = ".vso"
                break;
            case 5:
                fileType = "MSProject.Project";
                filedot = ".pro";
                break;
            case 6:
                fileType = "WPS Doc";
                filedot = ".wps";
                break;
            case 7:
                fileType = "Kingsoft Sheet";
                filedot = ".et";
                break;
            default:
                fileType = "unkownfiletype";
                filedot = ".doc";
        }
        retHTML = TANGER_OCX_OBJ.PublishAsHTMLToURL(savecode, //提交到的url地址
		"EDITFILE", //文件域的id，类似<input type=file id=upLoadFile 中的id
		"savetype=2&fileType=" + fileType,          //与控件一起提交的参数,savetype参数为要保存的文件格式office,html,pdf。filetype参数保存文件类型
		fileName + filedot + ".html",    //上传文件的名称，类似<input type=file 的value
		0  //与控件一起提交的表单id，也可以是form的序列号，这里应该是0.
		);
        newwin = window.open("", "_blank", "left=200,top=200,width=400,height=300,status=0,toolbar=0,menubar=0,location=0,scrollbars=1,resizable=1", false);
        newdoc = newwin.document;
        newdoc.open();
        newdoc.write("<center><hr>" + retHTML + "<hr><input type=button VALUE='关闭窗口' onclick='window.close();if(window.opener){window.opener.location.reload()};'></center>");
        newdoc.close();
        window.opener.focus();
    }
    else {
        alert("不能执行保存,没有编辑文档!");
    }
}
//保护文档为pdf格式
function saveFileAsPdfToUrl() {
    var fileName = trim(document.all("filetitle").value);
    if (fileName.length == 0) { alert("请输入文件标题!"); document.all("filetitle").focus(); return false; } //判断文件标题输入域
    var result, filedot;
    if (IsFileOpened && TANGER_OCX_OBJ.IsPDFCreatorInstalled()) {
        switch (TANGER_OCX_OBJ.doctype) {
            case 1:
                fileType = "Word.Document";
                filedot = ".doc";
                break;
            case 2:
                fileType = "Excel.Sheet";
                filedot = ".xls";
                break;
            case 3:
                fileType = "PowerPoint.Show";
                filedot = ".ppt";
                break;
            case 4:
                fileType = "Visio.Drawing";
                filedot = ".vso"
                break;
            case 5:
                fileType = "MSProject.Project";
                filedot = ".pro";
                break;
            case 6:
                fileType = "WPS Doc";
                filedot = ".wps";
                break;
            case 7:
                fileType = "Kingsoft Sheet";
                filedot = ".et";
                break;
            default:
                fileType = "unkownfiletype";
                filedot = ".doc";
        }
        TANGER_OCX_OBJ.PublishAsPDFToURL(savecode, //提交到的url地址
		"EDITFILE", //文件域的id，类似<input type=file id=upLoadFile 中的id
		"savetype=3&fileType=" + fileType,          //与控件一起提交的参数,savetype参数为要保存的文件格式office,html,pdf。filetype参数保存文件类型
		fileName + filedot,    //上传文件的名称，类似<input type=file 的value
		0,  //与控件一起提交的表单id，也可以是form的序列号，这里应该是0.
		null, //sheetname,保存excel的哪个表格
	    true, //IsShowUI,是否显示保存界面
	    false, // IsShowMsg,是否显示保存成功信息
	    false, // IsUseSecurity,是否使用安全特性
	    null, // OwnerPass,安全密码.可直接传值
	    false, //IsPermitPrint,是否允许打印
	    true //IsPermitCopy,是否允许拷贝
		);
    }
    else {
        alert("不能执行保存,没有编辑文档或者没有安装PDF虚拟打印机!");
    }
}



//保存office文档
function saveFileToUrlNew(redirectUrl) {
    var fileName = trim(document.all("filetitle").value);
    if (fileName.length == 0) { alert("请输入文件标题!"); document.all("filetitle").focus(); return false; } //判断文件标题输入域
    var result, filedot;
    if (IsFileOpened) {
        switch (TANGER_OCX_OBJ.doctype) {
            case 1:
                fileType = "Word.Document";
                filedot = ".doc";
                break;
            case 2:
                fileType = "Excel.Sheet";
                filedot = ".xls";
                break;
            case 3:
                fileType = "PowerPoint.Show";
                filedot = ".ppt";
                break;
            case 4:
                fileType = "Visio.Drawing";
                filedot = ".vso"
                break;
            case 5:
                fileType = "MSProject.Project";
                filedot = ".pro";
                break;
            case 6:
                fileType = "WPS Doc";
                filedot = ".wps";
                break;
            case 7:
                fileType = "Kingsoft Sheet";
                filedot = ".et";
                break;
            default:
                fileType = "unkownfiletype";
                filedot = ".doc";
        }

        retHTML = TANGER_OCX_OBJ.saveToURL(savecode, //提交到的url地址
		"EDITFILE", //文件域的id，类似<input type=file id=upLoadFile 中的id
		"savetype=1&fileType=" + fileType,          //与控件一起提交的参数,savetype参数为要保存的文件格式office,html,pdf。filetype参数保存文件类型
		fileName + filedot,    //上传文件的名称，类似<input type=file 的value
		0  //与控件一起提交的表单id，也可以是form的序列号，这里应该是0.
		);


        if (retHTML != "") {
            var strMessages = retHTML.split('|');
            var message = strMessages[0];
            switch (message) {
//                case "ok":
//                    {
//                        alert("保存成功!");
//                        window.location.href = strMessages[1];
//                    } break;
                case "error": alert(strMessages[1]); break;
                default:
                    alert("保存成功!");
                    if (window.opener != null) {
                        if (typeof (redirectUrl) != "undefined") {
                            window.opener.location.href = redirectUrl + editMSOthePara;
                        }
                        else {
                            window.opener.location.href = "managerDocList.aspx?" + editMSOthePara;
                        }

                    } else {
                        window.returnValue = 1;
                    }
                    window.close();
            }
        } 
    }
    else {
        alert("不能执行保存,没有编辑文档!");
    }
}



function testFunction() {
    alert(IsFileOpened);
}
function addServerSecSign() {
    var signUrl = document.all("secSignFileUrl").options[document.all("secSignFileUrl").selectedIndex].value;
    if (IsFileOpened) {
        if (TANGER_OCX_OBJ.doctype == 1 || TANGER_OCX_OBJ.doctype == 2) {
            try
			{ TANGER_OCX_OBJ.AddSecSignFromURL("ntko", signUrl); }
            catch (error) { }
        }
        else
        { alert("不能在该类型文档中使用安全签名印章."); }
    }
}
function addLocalSecSign() {
    if (IsFileOpened) {
        if (TANGER_OCX_OBJ.doctype == 1 || TANGER_OCX_OBJ.doctype == 2) {
            try
			{ TANGER_OCX_OBJ.AddSecSignFromLocal("ntko", ""); }
            catch (error) { }
        }
        else
        { alert("不能在该类型文档中使用安全签名印章."); }
    }
}
function addEkeySecSign() {
    if (IsFileOpened) {
        if (TANGER_OCX_OBJ.doctype == 1 || TANGER_OCX_OBJ.doctype == 2) {
            try
			{ TANGER_OCX_OBJ.AddSecSignFromEkey("ntko"); }
            catch (error) { }
        }
        else
        { alert("不能在该类型文档中使用安全签名印章."); }
    }
}
function addHandSecSign() {
    if (IsFileOpened) {
        if (TANGER_OCX_OBJ.doctype == 1 || TANGER_OCX_OBJ.doctype == 2) {
            try
			{ TANGER_OCX_OBJ.AddSecHandSign("ntko"); }
            catch (error) { }
        }
        else
        { alert("不能在该类型文档中使用安全签名印章."); }
    }
}

function addServerSign(signUrl) {
    if (IsFileOpened) {
        try {
            TANGER_OCX_OBJ.AddSignFromURL("ntko", //印章的用户名
				signUrl, //印章所在服务器相对url
				100, //左边距
				100, //上边距 根据Relative的设定选择不同参照对象
				"ntko", //调用DoCheckSign函数签名印章信息,用来验证印章的字符串
				3,  //Relative,取值1-4。设置左边距和上边距相对以下对象所在的位置 1：光标位置；2：页边距；3：页面距离 4：默认设置栏，段落
				100, //缩放印章,默认100%
				1);   //0印章位于文字下方,1位于上方

        }
        catch (error) { }
    }
}

function addLocalSign() {
    if (IsFileOpened) {
        try {
            TANGER_OCX_OBJ.AddSignFromLocal("ntko", //印章的用户名
					"", //缺省文件名
					true, //是否提示选择
					100, //左边距
					100, //上边距 根据Relative的设定选择不同参照对象
					"ntko", //调用DoCheckSign函数签名印章信息,用来验证印章的字符串
					3,  //Relative,取值1-4。设置左边距和上边距相对以下对象所在的位置 1：光标位置；2：页边距；3：页面距离 4：默认设置栏，段落
					100, //缩放印章,默认100%
					1);   //0印章位于文字下方,1位于上方
        }
        catch (error) { }
    }
}
function addPicFromUrl(picURL) {
    if (IsFileOpened) {
        if (TANGER_OCX_OBJ.doctype == 1 || TANGER_OCX_OBJ.doctype == 2) {
            try {
                TANGER_OCX_OBJ.AddPicFromURL(picURL, //图片的url地址可以时相对或者绝对地址
				false, //是否浮动,此参数设置为false时,top和left无效
				100, //left 左边距
				100, //top 上边距 根据Relative的设定选择不同参照对象
				1,  //Relative,取值1-4。设置左边距和上边距相对以下对象所在的位置 1：光标位置；2：页边距；3：页面距离 4：默认设置栏，段落
				100, //缩放印章,默认100%
				1);   //0印章位于文字下方,1位于上方

            }
            catch (error) { }
        }
        else
        { alert("不能在该类型文档中使用安全签名印章."); }
    }
}
function addPicFromLocal() {
    if (IsFileOpened) {
        try {
            TANGER_OCX_OBJ.AddPicFromLocal("", //印章的用户名
					true, //缺省文件名
					false, //是否提示选择
					100, //左边距
					100, //上边距 根据Relative的设定选择不同参照对象
					1,  //Relative,取值1-4。设置左边距和上边距相对以下对象所在的位置 1：光标位置；2：页边距；3：页面距离 4：默认设置栏，段落
					100, //缩放印章,默认100%
					1);   //0印章位于文字下方,1位于上方
        }
        catch (error) { }
    }
}

function TANGER_OCX_AddDocHeader(strHeader) {
    if (!IsFileOpened)
    { return; }
    var i, cNum = 30;
    var lineStr = "";
    try {
        for (i = 0; i < cNum; i++) lineStr += "_";  //生成下划线
        with (TANGER_OCX_OBJ.ActiveDocument.Application) {
            Selection.HomeKey(6, 0); // go home
            Selection.TypeText(strHeader);
            Selection.TypeParagraph(); 	//换行
            Selection.TypeText(lineStr);  //插入下划线
            // Selection.InsertSymbol(95,"",true); //插入下划线
            Selection.TypeText("★");
            Selection.TypeText(lineStr);  //插入下划线
            Selection.TypeParagraph();
            //Selection.MoveUp(5, 2, 1); //上移两行，且按住Shift键，相当于选择两行
            Selection.HomeKey(6, 1);  //选择到文件头部所有文本
            Selection.ParagraphFormat.Alignment = 1; //居中对齐
            with (Selection.Font) {
                NameFarEast = "宋体";
                Name = "宋体";
                Size = 12;
                Bold = false;
                Italic = false;
                Underline = 0;
                UnderlineColor = 0;
                StrikeThrough = false;
                DoubleStrikeThrough = false;
                Outline = false;
                Emboss = false;
                Shadow = false;
                Hidden = false;
                SmallCaps = false;
                AllCaps = false;
                Color = 255;
                Engrave = false;
                Superscript = false;
                Subscript = false;
                Spacing = 0;
                Scaling = 100;
                Position = 0;
                Kerning = 0;
                Animation = 0;
                DisableCharacterSpaceGrid = false;
                EmphasisMark = 0;
            }
            Selection.MoveDown(5, 3, 0); //下移3行
        }
    }
    catch (err) {
        alert("错误：" + err.number + ":" + err.description);
    }
    finally {
    }
}

function insertRedHeadFromUrl(headFileURL) {
    if (TANGER_OCX_OBJ.doctype != 1)//TANGER_OCX_OBJ.doctype=1为word文档
    { return; }
    TANGER_OCX_OBJ.ActiveDocument.Application.Selection.HomeKey(6, 0); //光标移动到文档开头
    TANGER_OCX_OBJ.addtemplatefromurl(headFileURL); //在光标位置插入红头文档
}
function insertRedButtomFromUrl(headFileURL) {
    if (TANGER_OCX_OBJ.doctype != 1)//TANGER_OCX_OBJ.doctype=1为word文档
    { return; }
    TANGER_OCX_OBJ.ActiveDocument.Application.Selection.EndKey(6, 0);
    TANGER_OCX_OBJ.ActiveDocument.Application.Selection.TypeParagraph();
    TANGER_OCX_OBJ.addtemplatefromurl(headFileURL); //在光标位置插入红头文档
}
function openTemplateFileFromUrl(templateUrl) {
    TANGER_OCX_OBJ.openFromUrl(templateUrl);
}
function doHandSign() {
    /*if(TANGER_OCX_OBJ.doctype==1||TANGER_OCX_OBJ.doctype==2)//此处设置只允许在word和excel中盖章.doctype=1是"word"文档,doctype=2是"excel"文档
    {*/
    TANGER_OCX_OBJ.DoHandSign2(
									"ntko", //手写签名用户名称
									"ntko", //signkey,DoCheckSign(检查印章函数)需要的验证密钥。
									0, //left
									0, //top
									1, //relative,设定签名位置的参照对象.0：表示按照屏幕位置插入，此时，Left,Top属性不起作用。1：光标位置；2：页边距；3：页面距离 4：默认设置栏，段落（为兼容以前版本默认方式）
									100);
    //}
}
function SetReviewMode(boolvalue) {
    if (TANGER_OCX_OBJ.doctype == 1) {
        TANGER_OCX_OBJ.ActiveDocument.TrackRevisions = boolvalue; //设置是否保留痕迹
    }
}

function setShowRevisions(boolevalue) {
    if (TANGER_OCX_OBJ.doctype == 1) {
        TANGER_OCX_OBJ.ActiveDocument.ShowRevisions = boolevalue; //设置是否显示痕迹
    }
}
//接受或者取消所有修订
function TANGER_OCX_AllRevisions(bool) {
    if (bool) {
        TANGER_OCX_OBJ.ActiveDocument.AcceptAllRevisions(); //接受所有的痕迹修订
    }
    else {
        TANGER_OCX_OBJ.ActiveDocument.Application.WordBasic.RejectAllChangesInDoc(); //拒绝所有的痕迹修订
    }
}
function setFilePrint(boolvalue) {
    TANGER_OCX_OBJ.fileprint = boolvalue; //是否允许打印
}
function setFileNew(boolvalue) {
    TANGER_OCX_OBJ.FileNew = boolvalue; //是否允许新建
}
function setFileSaveAs(boolvalue) {
    TANGER_OCX_OBJ.FileSaveAs = boolvalue; //是否允许另存为
}

function setIsNoCopy(boolvalue) {
    TANGER_OCX_OBJ.IsNoCopy = boolvalue; //是否禁止粘贴
}
function DoCheckSign() {
    if (IsFileOpened) {
        var ret = TANGER_OCX_OBJ.DoCheckSign
			(
			false, /*可选参数 IsSilent 缺省为FAlSE，表示弹出验证对话框,否则，只是返回验证结果到返回值*/
			"ntko"//使用盖章时的signkey,这里为"ntko"
			); //返回值，验证结果字符串
        //alert(ret);
    }
}
function setToolBar() {
    TANGER_OCX_OBJ.ToolBars = !TANGER_OCX_OBJ.ToolBars;
}
function setMenubar() {
    TANGER_OCX_OBJ.Menubar = !TANGER_OCX_OBJ.Menubar;
}
function setInsertMemu() {
    TANGER_OCX_OBJ.IsShowInsertMenu = !TANGER_OCX_OBJ.IsShowInsertMenu;
}
function setEditMenu() {
    TANGER_OCX_OBJ.IsShowEditMenu = !TANGER_OCX_OBJ.IsShowEditMenu;
}
function setToolMenu() {
    TANGER_OCX_OBJ.IsShowToolMenu = !TANGER_OCX_OBJ.IsShowToolMenu;
}

//增加自定义菜单
function initCustomMenus1() {
    var myobj = TANGER_OCX_OBJ;
    for (var menuPos = 0; menuPos < 1; menuPos++) {
        myobj.AddCustomMenu2(menuPos, "常用功能" + "(&" + menuPos + ")");
        for (var submenuPos = 0; submenuPos < 1; submenuPos++) {
            myobj.AddCustomMenuItem2(menuPos, submenuPos, -1, true, "打印设置", false);
            //增加子菜单项目
            for (var subsubmenuPos = 0; subsubmenuPos < 3; subsubmenuPos++) {
                if (0 == subsubmenuPos)//增加子菜单项目
                {
                    myobj.AddCustomMenuItem2(menuPos, submenuPos, subsubmenuPos, false,
							"设置打印区域", false, menuPos * 100 + submenuPos * 20 + subsubmenuPos);
                }
                if (1 == subsubmenuPos)//增加子菜单项目
                {
                    myobj.AddCustomMenuItem2(menuPos, submenuPos, subsubmenuPos, false,
							"取消打印区域", false, menuPos * 100 + submenuPos * 20 + subsubmenuPos);
                }
                if (2 == subsubmenuPos) {
                    myobj.AddCustomMenuItem2(menuPos, submenuPos, subsubmenuPos, false,
							"手写批注", false, menuPos * 100 + submenuPos * 20 + subsubmenuPos);
                }
            }
        }
    }
}
//控件控制
function controlStyle() {
    var myobj = TANGER_OCX_OBJ;
    for (var menuPos = 0; menuPos < 1; menuPos++) {
        myobj.AddCustomMenu2(menuPos, "控件样式" + "(&" + menuPos + ")");
        for (var submenuPos = 0; submenuPos < 1; submenuPos++) {
            myobj.AddCustomMenuItem2(menuPos, submenuPos, -1, true, "改变大小", false);
            //增加子菜单项目
            for (var subsubmenuPos = 0; subsubmenuPos < 2; subsubmenuPos++) {
                if (0 == subsubmenuPos)//增加子菜单项目
                {
                    myobj.AddCustomMenuItem2(menuPos, submenuPos, subsubmenuPos, false,
							"全网页查看", false, menuPos * 100 + submenuPos * 20 + subsubmenuPos);
                }
                if (1 == subsubmenuPos)//增加子菜单项目
                {
                    myobj.AddCustomMenuItem2(menuPos, submenuPos, subsubmenuPos, false,
							"恢复原大小", false, menuPos * 100 + submenuPos * 20 + subsubmenuPos);
                }
            }
        }
    }
}
//改变控件大小为当前网页可见区域
function objside() {
    document.all.officecontrol.style.position = "absolute";
    document.all.officecontrol.style.left = "0px";
    document.all.officecontrol.style.top = "0px";
    document.all.officecontrol.style.width = document.body.clientWidth; //网页可见区域宽
    document.all.officecontrol.style.height = document.body.clientHeight; //网页可见区域高
}
//恢复控件显示大小
function objside2() {
    document.all.officecontrol.style.position = "relative";
    document.all.officecontrol.style.left = "0px";
    document.all.officecontrol.style.top = "0px";
    document.all.officecontrol.style.width = "100%";
    document.all.officecontrol.style.height = "980px";
}
//显示或隐藏文档控件对象
function ObjectDisplay(boolvalue) {
    var obj = document.getElementById("objside");
    if (!boolvalue) {
        obj.style.display = "none";
    }
    else {
        obj.style.display = "block";
    }
}
function PrintFile() {
    TANGER_OCX_OBJ.PrintOut();
}